package com.ybxx.hr.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.util.UUIDGenerator;
import com.ybxx.core.web.action.BaseAction;
import com.ybxx.hr.model.Dept;
import com.ybxx.hr.service.DeptService;

public class DeptAction extends BaseAction {
	@Resource
	private DeptService deptService;
	private List<Dept> depts;
	private Dept dept;
	private String msg="succ";
	/*删除*/
	public String remove(){
		try{
			deptService.remove(dept.getDid());
		}catch(Exception ex){
			msg="部门删除失败";
		}finally{
			return "succ";
		}
	}
	/*加载查看时候需要展示的数据*/
	public String view(){
		if(dept!=null && StringUtils.isNotEmpty(dept.getDid())){
			dept=deptService.get(dept.getDid());
		}
		return "view";
	}
	public String queryPage(){
		QueryFilter filter=new QueryFilter(getRequest());
		depts=deptService.queryPage(dept,filter);
		super.setRownum(filter.getPagingBean().getTotalItems());
		super.setCurrentpage(Integer.parseInt(filter.getPagingBean().getStart()+"")/Integer.parseInt(filter.getPagingBean().getPageSize()+"")+1);
		super.setPageSize(Integer.parseInt(filter.getPagingBean().getPageSize()+""));
		return "queryPage";
	}
	/*保存新增，修改信息*/
	public String save(){
		if(StringUtils.isEmpty(dept.getDid())){
			dept.setDid(UUIDGenerator.getUUID());
		}
		try{
			deptService.save(dept);
		}catch(Exception ex){
			msg="部门信息保存失败.";
		}finally{
			return "succ";
		}
	}
	/*加载修改时候需要展示的数据*/
	public String load(){
		if(dept!=null && StringUtils.isNotEmpty(dept.getDid())){
			dept=deptService.get(dept.getDid());
		}
		return "load";
	}
	public List<Dept> getDepts() {
		return depts;
	}
	public void setDepts(List<Dept> depts) {
		this.depts = depts;
	}
	public Dept getDept() {
		return dept;
	}
	public void setDept(Dept dept) {
		this.dept = dept;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	
}
